package com.zzyl.controller;


import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "资源列表管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    //资源列表查询
    @PostMapping("/list")
    @ApiOperation(value = "资源列表",notes = "资源列表")
    @ApiImplicitParam(name = "resourceDto",value = "资源DTO对象",required = true,dataType = "ResourceDto")
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo> resourceVoList = resourceService.resourceList(resourceDto);
        return ResponseResult.success(resourceVoList);
    }
    //资源树形
    @PostMapping("/tree")
    @ApiOperation(value = "资源树形",notes = "资源树形")
    public ResponseResult<TreeVo> resourceTreeVo(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resourceTreeVo(resourceDto);
        return ResponseResult.success(treeVo);
    }
    //添加资源
    @PutMapping
    @ApiOperation(value = "添加资源",notes = "添加资源")
    @ApiImplicitParam(name = "resourceDto",value = "添加资源DTO对象",required = true,dataType = "resourceDto")
    public ResponseResult<ResourceVo> createResource(@RequestBody ResourceDto resourceDto) {
        return ResponseResult.success(resourceService.createResource(resourceDto));
    }
}
